package com.changgou.system;


import com.sun.scenario.effect.impl.sw.sse.SSEBlend_SRC_OUTPeer;
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.core.Ordered;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;
//配置网关过滤组件 实现GlObalFilter(全局过滤器)  (命令)Ordered接口
@Component
public class IpFilter implements GlobalFilter, Ordered{

    @Override
    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
        System.out.println("第一个过滤器,优先级为1");
//        String id = exchange.getRequest().getId();
//        System.out.println("id:"+id);
        //获取主机名
        String hostName = exchange.getRequest().getRemoteAddress().getHostName();
        System.out.println("ip:"+hostName);
        //释放请求.
        return chain.filter(exchange);
    }
    //拦截器优先级  越小优先级越高
    @Override
    public int getOrder() {
        return 1;
    }
}
